package com.agricultural.state.impl;

import com.agricultural.equipment.AgriculturalEquipment;
import com.agricultural.state.EquipmentState;

// 错误状态类
public class ErrorState implements EquipmentState {
    private AgriculturalEquipment equipment; // 设备引用
    private String errorMessage;             // 错误信息
    
    // 构造函数
    public ErrorState(AgriculturalEquipment equipment, String errorMessage) {
        this.equipment = equipment;
        this.errorMessage = errorMessage;
    }
    
    // 获取状态名称
    @Override
    public String getStateName() {
        return "错误";
    }
    
    // 获取错误信息
    public String getErrorMessage() {
        return errorMessage;
    }
    
    // 启动设备
    @Override
    public void start() {
        System.out.println("[" + equipment.getType() + "-" + equipment.getId() + "] 存在错误: " + errorMessage + "，无法启动");
    }
    
    // 停止设备
    @Override
    public void stop() {
        System.out.println("[" + equipment.getType() + "-" + equipment.getId() + "] 正在停止，错误: " + errorMessage);
        equipment.updateState(new IdleState(equipment));
    }
    
    // 执行作业
    @Override
    public void executeWork() {
        System.out.println("[" + equipment.getType() + "-" + equipment.getId() + "] 存在错误: " + errorMessage + "，无法执行作业");
    }
    
    // 获取设备
    @Override
    public AgriculturalEquipment getEquipment() {
        return equipment;
    }
}    